<?php include_stylesheets_for_form($form) ?>
<?php include_javascripts_for_form($form) ?>

<?php
  $slide = $form->getObject();
  if ($slide->isNew()) {
    $section_collapsed = TRUE;
  }
  else {
    if ($slide->getSection() || $slide->getSubSection()) {
      $section_collapsed = FALSE;
    }
    else {
      $section_collapsed = TRUE;
    }
  }
  
?>

<form action="<?php echo url_for('slide/'.($slide->isNew() ? 'create' : 'update').(!$slide->isNew() ? '?token='. $slide->gettoken() : '?presentation='. $presentation->gettoken())) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?> id="form-slide">
  <?php echo $form->renderHiddenFields() ?>
  <?php if ($form->hasGlobalErrors()): ?>
    <ul class="error">
      <?php foreach ($form->getGlobalErrors() as $name => $error): ?>
        <li><?php echo $name.': '.$error ?></li>
      <?php endforeach; ?>
    </ul>
  <?php endif; ?>

  <?php if (!$form->getObject()->isNew()): ?>
    <input type="hidden" name="sf_method" value="put" />
  <?php endif; ?>

  <fieldset id="section" class="collapsible <?php echo $section_collapsed ? 'collapsed' : '' ?>">
    <legend>New section / subsection</legend>
    <div class="form-row">
      <?php echo $form['section']->renderLabel() ?>
      <?php echo $form['section']->renderError() ?>
      <?php echo $form['section']->render(array('class' => 'default')) ?>
      <?php echo $form['section_short']->renderLabel() ?>
      <?php echo $form['section_short']->renderError() ?>
      <?php echo $form['section_short']->render(array('class' => 'short')) ?>
    </div>
    <div class="form-row">
      <?php echo $form['subsection']->renderLabel() ?>
      <?php echo $form['subsection']->renderError() ?>
      <?php echo $form['subsection']->render(array('class' => 'default')) ?>
      <?php echo $form['subsection_short']->renderLabel() ?>
      <?php echo $form['subsection_short']->renderError() ?>
      <?php echo $form['subsection_short']->render(array('class' => 'short')) ?>
    </div>
    <div class="form-row">
      <?php echo $form['section_in_toc']->renderLabel() ?>
      <?php echo $form['section_in_toc']->renderError() ?>
      <?php echo $form['section_in_toc'] ?>
    </div>
  </fieldset>

  <fieldset id="slide">
    <legend>Slide</legend>
    <div class="form-row">
      <?php echo $form['title']->renderLabel() ?>
      <?php echo $form['title']->renderError() ?>
      <?php echo $form['title']->render(array('class' => 'long')) ?>
    </div>
    <div class="form-row">
      <?php echo $form['subtitle']->renderLabel() ?>
      <?php echo $form['subtitle']->renderError() ?>
      <?php echo $form['subtitle']->render(array('class' => 'long')) ?>
    </div>
    <div class="form-row">
      <?php echo $form['content']->renderLabel() ?>
      <?php echo $form['content']->renderError() ?>
      <?php echo $form['content']->render(array('class' => 'content resizable')) ?>
    </div>
    <div class="form-row">
      <?php echo $form['is_plain']->renderLabel() ?>
      <?php echo $form['is_plain']->renderError() ?>
      <?php echo $form['is_plain'] ?>
    </div>
  </fieldset>

  <div>
    <a href="<?php echo url_for('@presentation_show?token='.$presentation->gettoken()) ?>" class="button">Cancel</a>
    <?php if (!$form->getObject()->isNew()): ?>
      &nbsp;<?php echo link_to('Delete', '@slide_delete?token='.$form->getObject()->gettoken(), array('method' => 'delete', 'confirm' => 'Are you sure?', 'class' => 'button negative')) ?>
    <?php endif; ?>
    <button type="submit" class="button positive">Save</button>
  </div>

</form>
